package com.lizi.MarkHsiu;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

import com.lizi.core.util.SizeOfObject;

/**
 * 十进制转为其他进制
 * @author Mark Hsiu
 *
 */
public class Bit16 {

	
	
	public static void main(String[] args) throws Exception {
		
		char  a = 'a';
		
		System.out.println(a);
		System.out.println("1".getBytes().length);
		System.out.println(Bit16.size(new Ob()));
		
		System.out.println(Bit16.size(new Integer(0)));
		long num = 300;
		int bit  = 16;
		
		convertBit(num, bit);

	}
	
	public static int size(final Object o) throws IOException {
		  if (o == null) {
		   return 0;
		  }
		  ByteArrayOutputStream buf = new ByteArrayOutputStream(4096);
		  ObjectOutputStream out = new ObjectOutputStream(buf);
		  out.writeObject(o);
		  out.flush();
		  buf.close();

		  return buf.size();
		 }

	public static void convertBit(long num,int bit){
		StringBuffer result = new StringBuffer();
		int index = 0;
		while(true){
			result.insert(0, num % bit+",");
			num = num/bit;
			if(num == 0){
				break;
			}
			index ++;
		}
		System.out.println(result);
		
		String[] array = result.toString().split(",");
	
		for(String a : array){
			num += Integer.parseInt(a) * ((int)Math.pow(bit, index));
			index --;
		}
		System.out.println(num);
	}
	
}
